/**
 * umiHooks 接口
 * @author SPY
 * @date 2020/04/11
 */

import { request } from 'umi';

export async function queryList(params: any): Promise<any> {
  return request('https://randomuser.me/api/', { params });
}

// 在ProTable中使用
export async function queryProTableList(params: any): Promise<any> {
  return request('https://randomuser.me/api/', { params }).then(response => {
    if (Array.isArray(response.results)) {
      const data = response.results.map((item: any) => {
        return {
          name: item.name.title,
          gender: item.gender,
          picture: item.picture.large,
          email: item.email,
          uuid: item.login.uuid,
        };
      });
      return {
        data,
        success: true,
        page: params.current,
        total: params.total,
      };
    }
  });
}
